********************************************************************************
***
*** 	Replication files for Zhuang, Maiting. 2022.
***
*** 	"Intergovernmental Conflict and Censorship: Evidence from China's 
***
***		Anti-Corruption Campaign" 
***
***		Journal of the European Economic Association
***
********************************************************************************

*** 	Do-file for all Tables and Figures in Appendix A

clear

global dir "your directory path"

cd "$dir"


********************************************************************************
*** FIGURES
********************************************************************************

*** FIGURE A.1

use "$dir/data/ofnppost.dta",clear

merge m:1 of using "$dir/data/officials.dta", keepusing(of_high date_diff_inv_sen sentence_num)
drop if _merge==2
drop _merge

keep if of_high==1

bys of own_province post: egen mean_art_op = mean(article_post)

duplicates drop of own_province post,force

keep of own_province post mean_art_op of_high of_province date_diff_inv_sen sentence_num

gen j = 1 if post==0 &own_province==0
replace j = 2 if post==0 &own_province==1
replace j = 3 if post == 1 &own_province==0
replace j = 4 if post==1 &own_province==1

drop post own_province

reshape wide mean_art, i(of) j(j) 

rename mean_art_op* p*

gen ddiff = (p4-p3) - (p2-p1)

twoway lfitci  date_diff_inv_sen ddiff, lcolor(black) acolor(black) fcolor(gs5) fintensity(inten20) alstyle(dot) estopts(robust)  || ///
scatter  date_diff_inv_sen ddiff  if of_high==1, msymbol(circle) mcolor(black) scheme(s1mono) legend(off) ///
xtitle("Difference in mean daily probability of article publication" "between same- and other-province newspapers" "after vs before corruption investigation" , margin(medium))  ///
ytitle("Lag between investigation" "and sentencing (number of days)", margin(medium))
graph export "$dir/output/FigureA1a.pdf",replace

twoway lfitci  sentence_num ddiff, lcolor(black) acolor(black) fcolor(gs5) fintensity(inten20) alstyle(dot) estopts(robust)  || ///
scatter  sentence_num ddiff  if of_high==1, msymbol(circle) mcolor(black) scheme(s1mono) legend(off) ///
xtitle("Difference in mean daily probability of article publication" "between same- and other-province newspapers" "after vs before corruption investigation" , margin(medium))  ///
ytitle("Sentence severity: number of years in prison", margin(medium))
graph export "./output/FigureA1b.pdf",replace

********************************************************************************

*** FIGURE A.2

use "$dir/data/province_covariates.dta",clear
merge 1:1 prov_en using "$dir/data/prov_coefs.dta"
drop _merge

twoway lfitci  count_201516_Tiger coef, lcolor(black) acolor(black) fcolor(gs5) fintensity(inten20) alstyle(dot) estopts(robust)  || ///
scatter  count_201516_Tiger coef, msymbol(circle) mcolor(black) scheme(s1mono) legend(off) ///
xtitle("Coefficient" , margin(medium))  ///
ytitle("Number of officials investigated", margin(medium))
graph export "$dir/output/FigureA2a.pdf",replace

twoway lfitci  count_201516_Fly coef, lcolor(black) acolor(black) fcolor(gs5) fintensity(inten20) alstyle(dot) estopts(robust)  || ///
scatter  count_201516_Fly coef, msymbol(circle) mcolor(black) scheme(s1mono) legend(off) ///
xtitle("Coefficient" , margin(medium))  ///
ytitle("Number of officials investigated", margin(medium))
graph export "$dir/output/FigureA2b.pdf",replace


********************************************************************************

*** FIGURE A.3

use "$dir/data/ofnppost.dta",clear

merge m:1 np_name_cons using "$dir/data/newspapers.dta", keepusing(np_owner* np_coowned np_partypaper np_govtowned)
drop _merge

replace np_owner1="解放日报" if np_owner1=="上海报业"
replace np_name_cons="人民日报" if np_name_cons=="人民日报海外版"
replace np_name_cons="羊城晚报" if np_name_cons=="羊城晚报(全国版)"
replace np_name_cons=ustrtrim(np_name_cons)

gen byte owner_in_sample=0
forval i=1/3{
replace np_owner`i'=ustrtrim(np_owner`i')
levelsof np_owner`i', local(np_owner) clean
foreach n of local np_owner {
replace owner_in_sample=1 if np_name_cons=="`n'"
replace owner_in_sample=1 if ustrpos(np_name_cons,"`n'")>0
replace owner_in_sample=1 if ustrpos("`n'",np_name_cons)>0
}
}

drop if np_partypaper==1 & owner_in_sample==0
drop if np_partypaper==0&np_govtowned==1
drop if np_coowned==1

bys np_name_cons of_high own_province post: egen mean_art_op = mean(article_post)

duplicates drop  of_high own_province own_province post np_name_cons,force

keep own_province post mean_art_op of_high np_name_cons np_govtowned np_owner1

gen j = 1 if post==0 &own_province==0 & of_high==0
replace j = 2 if post==0 &own_province==1 & of_high==0
replace j = 3 if post==1 &own_province==0 & of_high==0
replace j = 4 if post==1 &own_province==1 & of_high==0
replace j = 5 if post==0 &own_province==0 & of_high==1
replace j = 6 if post==0 &own_province==1 & of_high==1
replace j = 7 if post==1 &own_province==0 & of_high==1
replace j = 8 if post==1 &own_province==1 & of_high==1

drop post own_province of_high

reshape wide mean_art, i(np_name_cons) j(j) 

rename mean_art_op* p*

gen ddiff_low = (p4-p3) - (p2-p1)
gen ddiff_high = (p8-p7) - (p6-p5)

gen diff_low_op = (p4-p2)
gen diff_high_op = (p8-p6)
gen diff_low_nop = (p3-p1)
gen diff_high_nop = (p7-p5)

drop p*

preserve
keep if np_govtowned==0
rename np_name_cons np_name_sub
rename *diff* *diff*_sub
save "$dir/data/npchart_sub.dta", replace
restore

drop if np_govtowned==0
drop np_owner1
rename np_name_cons np_owner1
merge 1:m np_owner1 using "$dir/data/npchart_sub.dta"
keep if _merge==3

twoway (scatter diff_high_op_sub diff_high_op, msymbol(D)) (function y=x, range(diff_high_op)) , scheme(s1mono)  yscale(r(0)) yline(0) ///
ytitle("Subsidiary commercial newspaper", margin(medium)) ///
	xscale(r(0(0.002)0.01)) xtitle("Parent newspaper (official party newspaper)", margin(medium)) xline(0) legend(off) 
graph export "$dir/output/FigureA3a.pdf", replace

twoway (scatter diff_high_nop_sub diff_high_nop, msymbol(D)) (function y=x, range(diff_high_nop_sub)) , scheme(s1mono) yscale(r(0)) yline(0) ///
ytitle("Subsidiary commercial newspaper", margin(medium)) ///
	xscale(r(0(0.002)0.01)) xtitle("Parent newspaper (official party newspaper)", margin(medium)) xline(0) legend(off) 
graph export "$dir/output/FigureA3b.pdf", replace

twoway (scatter diff_low_op_sub diff_low_op, msymbol(D)) (function y=x, range(diff_low_op)) , scheme(s1mono) yscale(r(0)) yline(0) ///
ytitle("Subsidiary commercial newspaper", margin(medium)) ///
	xscale(r(0(0.002)0.01)) xtitle("Parent newspaper (official party newspaper)", margin(medium)) xline(0) legend(off) xlabel(#9)
graph export "$dir/output/FigureA3c.pdf", replace

twoway (scatter diff_low_nop_sub diff_low_nop, msymbol(D)) (function y=x, range(diff_low_nop_sub)) , scheme(s1mono) yscale(r(0)) yline(0) ///
ytitle("Subsidiary commercial newspaper", margin(medium)) ///
	xscale(r(0(0.002)0.01)) xtitle("Parent newspaper (official party newspaper)", margin(medium)) xline(0) legend(off) xlabel(#9)
graph export "$dir/output/FigureA3d.pdf", replace

********************************************************************************

*** FIGURE A.4

use "$dir/data/ofnppost.dta",clear

merge m:1 np_name_cons using "$dir/data/newspapers.dta", keepusing(l_ads)
drop _merge

bys np_name_cons of_high own_province post: egen mean_art_op = mean(article_post)

duplicates drop of_high own_province own_province post np_name_cons,force

keep own_province post mean_art_op of_high np_name_cons l_ads

gen j = 1 if post==0 &own_province==0 & of_high==0
replace j = 2 if post==0 &own_province==1 & of_high==0
replace j = 3 if post==1 &own_province==0 & of_high==0
replace j = 4 if post==1 &own_province==1 & of_high==0
replace j = 5 if post==0 &own_province==0 & of_high==1
replace j = 6 if post==0 &own_province==1 & of_high==1
replace j = 7 if post==1 &own_province==0 & of_high==1
replace j = 8 if post==1 &own_province==1 & of_high==1

drop post own_province of_high

reshape wide mean_art, i(np_name_cons) j(j) 

rename mean_art_op* p*

gen pdiff_low = (p4-p3)
gen pdiff_high = (p8-p7)

twoway lfitci pdiff_high l_ads, lcolor(black) acolor(black) fcolor(gs5) fintensity(inten20) alstyle(dot) estopts(robust) || ///
scatter pdiff_high l_ads, msymbol(circle) mcolor(black) scheme(s1mono) legend(off) ///
xtitle("Advertising revenue in 2011 (ln RMB)" , margin(medium))  ///
ytitle("Difference in the probability of publishing articles" "about officials from the same vs. other provinces", margin(medium))
graph export "$dir/output/FigureA4a.pdf",replace

twoway lfitci pdiff_low l_ads , lcolor(black) acolor(black) fcolor(gs5) fintensity(inten20) alstyle(dot) estopts(robust) || ///
scatter pdiff_low l_ads , msymbol(circle) mcolor(black) scheme(s1mono) legend(off) ///
xtitle("Advertising revenue in 2011 (ln RMB)" , margin(medium))  ysc(r(0 (0.01) 0.02)) ylabel(0 (0.01) 0.02) ///
ytitle("Difference in the probability of publishing articles" "about officials from the same vs. other provinces", margin(medium))
graph export "$dir/output/FigureA4b.pdf",replace

********************************************************************************

*** FIGURE A.5 

use "$dir/data/province_covariates.dta",clear
merge 1:1 prov_en using "$dir/data/prov_coefs.dta"
drop _merge

twoway lfitci coef np_count_qsw, lcolor(black) acolor(black) fcolor(gs5) fintensity(inten20) alstyle(dot) estopts(robust)  || ///
scatter coef np_count_qsw, msymbol(circle) mcolor(black) scheme(s1mono) legend(off) ///
xtitle("Number of newspapers in 2011" , margin(medium))  ///
ytitle("", margin(medium))
graph export "$dir/output/FigureA5a.pdf",replace

twoway lfitci coef ln_gdp, lcolor(black) acolor(black) fcolor(gs5) fintensity(inten20) alstyle(dot) estopts(robust)  || ///
scatter coef ln_gdp, msymbol(circle) mcolor(black) scheme(s1mono) legend(off) ///
xtitle("Nominal GDP in 2011, ln" , margin(medium))  ///
ytitle("", margin(medium))
graph export "$dir/output/FigureA5b.pdf",replace


********************************************************************************
*** TABLES
********************************************************************************

*** Table A.1

*** Newspapers

use "$dir/data/newspapers.dta",clear

estpost summarize np_partypaper np_nonpartygovt np_subsidiary np_central np_provincial np_subprovincial
esttab using "$dir/output/TableA1a.tex", ///
	cells(" mean(fmt(2)) sd(fmt(2)) min(fmt(0)) max(fmt(0)) count(fmt(0))") ///
	label fragment replace collabels(none) noobs nomtitle nonumber nolines booktabs   

*** Officials

use "$dir/data/officials.dta", clear

estpost su of_high of_govt  of_locgovt of_locprovince of_locsubprov  of_soe of_institution
esttab using "$dir/output/TableA1b.tex", ///
	cells(" mean(fmt(2)) sd(fmt(2)) min(fmt(0)) max(fmt(0)) count(fmt(0))") ///
	label fragment replace collabels(none) noobs nomtitle nonumber booktabs nolines

*** Articles

use "$dir/data/articles.dta",clear

estpost su art_words 
esttab using "$dir/output/TableA1c.tex", ///
	cells(" mean(fmt(0)) sd(fmt(0)) min(fmt(0)) max(fmt(0)) count(fmt(%16.0fc))") ///
	label fragment replace collabels(none) noobs nomtitle nonumber booktabs nolines

estpost su art_image art_page
esttab using "$dir/output/TableA1c.tex", ///
	cells(" mean(fmt(2)) sd(fmt(2)) min(fmt(0)) max(fmt(0)) count(fmt(%16.0fc))") ///
	label fragment append collabels(none) noobs nomtitle nonumber booktabs nolines

estpost su  art_articles_bal art_multipleofficial art_txtdenounce art_headline_copy art_hlcorrupt art_hlccdi  if art_post==1
esttab using "$dir/output/TableA1c.tex", ///
	cells(" mean(fmt(2)) sd(fmt(2)) min(fmt(0)) max(fmt(0)) count(fmt(%16.0fc))") ///
	label fragment append collabels(none) noobs nomtitle nonumber booktabs nolines
	
		
*** Panel

use "$dir/data/ofnppanel.dta",clear

estpost su article number own_province
esttab using "$dir/output/TableA1d.tex", ///
	cells(" mean(fmt(3)) sd(fmt(3)) min(fmt(0)) max(fmt(0)) count(fmt(%16.0fc))") ///
	label fragment replace collabels(none) noobs nomtitle nonumber booktabs nolines
	
********************************************************************************

*** TABLE A.2

use "$dir/data/ofnppanel.dta",clear

reghdfe article i.ophigh_ftx i.high_ftx i.dofw i.month i.year date_cny_broad date_duanwu_broad date_zhongqiu_broad date_congress date_committee date_zhengxie date_renda ccpprov lhprov if of_high==1, absorb(onid) vce(cluster np of)
estadd ysumm

test 1.ophigh_ftx=4.ophigh_ftx
estadd scalar p1=r(p)
test 3.ophigh_ftx=4.ophigh_ftx
estadd scalar p2=r(p)
test 1.high_ftx=4.high_ftx
estadd scalar p3=r(p)
test 2.high_ftx=4.high_ftx
estadd scalar p4=r(p)
test 3.high_ftx=4.high_ftx
estadd scalar p5=r(p)

esttab using "$dir/output/TableA2.tex", ///
	refcat(1.ophigh_ftx "\shortstack[l]{High-level official x\\Post-scandal x Same province\\From following faction:}" ///
	1.high_ftx "\shortstack[l]{High-level official x\\Post-scandal\\From following faction:}",nolabel) ///
	keep(*high_ftx) b(a2) se(a2) /// 
	replace interaction(" x ") star(* 0.10 ** 0.05 *** 0.01) booktabs noomitted nobaselevels noobs ///
	order(1.ophigh_ftx  3.ophigh_ftx   4.ophigh_ftx  1.high_ftx  2.high_ftx 3.high_ftx  4.high_ftx ) ///
	fragment nonumbers nolines nodepvar nomtitle varlabels(1.ophigh_ftx "CYLC" 3.ophigh_ftx  "Princeling"  4.ophigh_ftx "none" 1.high_ftx "CYLC" 3.high_ftx  "Princeling"  4.high_ftx "none" 2.high_ftx "Military") ///
	stats(p1 p2 p3 p4  p5 N r2 ymean,  fmt(a2 a2 a2 a2 a2  %16.0fc a2 a2 ) label("p(CYLC = none) - same province" "p(Princeling = none) - same province" "p(CYLC = none) - other province" "p(Military = none) - other province" "p(Princeling = none) - other province" "No. of obs." "R-squared" "Mean dep. var.")) 


********************************************************************************

*** TABLE A.3

use "$dir/data/baidu_reg.dta",clear

estimates clear
reg index own_province_high own_province_low , vce(clust of) 
estadd ysumm
estimates store m1
areg index own_province_high own_province_low i.prov, absorb (of) vce(clust of) 
estadd ysumm
estimates store m2
reg index own_province_high own_province_low if np_sample==1 , vce(clust of) 
estadd ysumm
estimates store m3
areg index own_province_high own_province_low i.prov  if np_sample==1, absorb (of) vce(clust of) 
estadd ysumm
estimates store m4

label variable own_province_high "\shortstack[l]{High-level official\\from same province}"
label variable own_province_low "\shortstack[l]{Low-level official\\from same province}"

esttab m1  m2 m3 m4 using "$dir/output/TableA3.tex" , keep(own_province_high own_province_low) ///
	refcat(own_province_high " " own_province_low " ", below nolabel) ///
	b(a2) se(a2) /// 
	prefoot(`"\addlinespace"' ///
	`"User province FE		&  & \checkmark  &  & \checkmark  \\ "' ///
	`"Official FE		&  & \checkmark  &  & \checkmark  \\ "' ///
	`"\midrule"') ///
	replace label  star(* 0.10 ** 0.05 *** 0.01) booktabs noomitted nobaselevels noobs ///
	fragment nonumbers nolines nodepvar nomtitle ///
	stats(N r2 ymean,  fmt(%16.0fc a2 a2 ) label(  "No. of obs." "R-squared" "Mean dep. var.")) 
